import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class Xpath:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get("https://www.baidu.com")
        self.driver.maximize_window()

    # 根据标签和属性定位搜索框
    def search(self):
        print(self.driver.find_element(By.XPATH, "//input[@id='kw']").get_attribute("outerHTML"))
        print(self.driver.find_element(By.XPATH, "//input[@class='s_ipt']").get_attribute("outerHTML"))
        print(self.driver.find_element(By.XPATH, "//input[@maxlength='255']").get_attribute("outerHTML"))

    def quit(self, seconds=3):
        time.sleep(seconds)
        self.driver.quit()


if __name__ == '__main__':
    IS = Xpath()
    IS.search()
    IS.quit()
